package com.htandroid.htandroid.webservice;

import android.util.Xml;

import com.htandroid.htandroid.entity.Htzc_Pvouch;
import com.htandroid.htandroid.entity.SplcLinesChar;

import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParser;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class abXMLHtzcPvouchlist {

    /**
     * 解析评论xml信息
     *
     * @param content
     * @return
     */
    public static ArrayList<Htzc_Pvouch> paraseCommentInfors(String content) {
        List<String> list = new ArrayList<String>();
        content = content.replace("Htzc_Pvouch=anyType", "#=#");
        String[] strs = content.split("#=");
        for (int i = 0; i < strs.length; i++) {
            if (strs[i].contains("#")) {
                list.add(strs[i].replace("#", "").trim().replace(" ", ""));
            }
        }
        ArrayList<Htzc_Pvouch> zcpvouchlist = new ArrayList<Htzc_Pvouch>();
        for (int i = 0; i < list.size(); i++) {
            if (i == list.size() - 1) {
                list.set(i, list.get(i).replace(";};};}", "\"}"));
            }
            list.set(i, list.get(i).replace(";};", "\"}").replace("=", "\":\"").replace(";", "\",\"").replace("{autoid", "{\"autoid"));
            try {
                Htzc_Pvouch info = new Htzc_Pvouch();
                JSONObject dataJson = new JSONObject(list.get(i));
                info.setAutoid(string2null(dataJson.getString("autoid")));
                info.setCchecker(string2null(dataJson.getString("cchecker")));
                info.setCmaker(string2null(dataJson.getString("cmaker")));
                info.setCmemo(string2null(dataJson.getString("cmemo")));
                info.setCvouchid(string2null(dataJson.getString("cvouchid")));
                info.setDdate(string2null(dataJson.getString("ddate")));
                info.setSdepts(string2null(dataJson.getString("sdepts")));
                info.setZcasscheckercode(string2null(dataJson.getString("zcasscheckercode")));
                info.setZcasscheckername(string2null(dataJson.getString("zcasscheckername")));
                info.setZccheckercode(string2null(dataJson.getString("zccheckercode")));
                info.setZccheckername(string2null(dataJson.getString("zccheckername")));
                zcpvouchlist.add(info);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return zcpvouchlist;
    }

    //函数作用是把null 转为空
    public static String string2null(String str) {
        String rtn = "";
        if (str == null || str.equals("null") || str.equals("anyType{}")) {
            rtn = "";
        } else {
            rtn = str;
        }
        return rtn;
    }
}
